home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / By the Book / Mac Pascal Primer, 4.0 / Chap 7, Sounder ƒ / Sounder.p next >
Text File  |  1990-06-22  |  2KB  |  96 lines

  1. {--------------------------------------------}
  2. {    Sounder can be found in Chapter Seven of        }
  3. {    The Macintosh Pascal Programming Primer.     }
  4. {                                                        }
  5. {    This source code is Copyright 1990,             }
  6. {    by Dave Mark and Cartwright Reed!!!            }
  7. {                                                        }
  8. {    Refer to the WindowMaker project (found        }
  9. {    in Chapter Seven) for a more complete            }
  10. {    example of a standalone Macintosh                }
  11. {    application.                                        }
  12. {--------------------------------------------}
  13.  
  14. program Sounder;
  15.     uses
  16.         Sound;
  17.  
  18.     const
  19.         BASE_RES_ID = 400;
  20.         SYNCHRONOUS = FALSE;
  21.  
  22.         ERROR_ALERT_ID = BASE_RES_ID + 1;
  23.         CANT_LOAD_BEEP_SND = BASE_RES_ID;
  24.         CANT_LOAD_MONKEY_SND = BASE_RES_ID + 1;
  25.         CANT_LOAD_KLANK_SND = BASE_RES_ID + 2;
  26.         CANT_LOAD_BOING_SND = BASE_RES_ID + 3;
  27.  
  28.         NIL_STRING = '';
  29.         HOPELESSLY_FATAL_ERROR = 'Game over, man!';
  30.  
  31.         BEEP_SND = 1;
  32.         MONKEY_SND = 2;
  33.         KLANK_SND = 3;
  34.         BOING_SND = 4;
  35.  
  36.  
  37. {-------------------------------->    ErrorHandler    <---}
  38.  
  39.     procedure ErrorHandler (stringNum: INTEGER);
  40.         var
  41.             errorStringH: StringHandle;
  42.             dummy: INTEGER;
  43.     begin
  44.         errorStringH := GetString(stringNum);
  45.         if errorStringH = nil then
  46.             ParamText(HOPELESSLY_FATAL_ERROR, NIL_STRING, NIL_STRING, NIL_STRING)
  47.         else
  48.             ParamText(errorStringH^^, NIL_STRING, NIL_STRING, NIL_STRING);
  49.  
  50.         dummy := StopAlert(ERROR_ALERT_ID, nil);
  51.         ExitToShell;
  52.     end;
  53.  
  54.  
  55. {-------------------------------->    MakeSound    <---}
  56.  
  57.     procedure MakeSound;
  58.         var
  59.             soundHandle: Handle;
  60.             dummy: OSErr;
  61.     begin
  62.         soundHandle := GetResource('snd ', BEEP_SND);
  63.  
  64.         if soundHandle = nil then
  65.             ErrorHandler(CANT_LOAD_BEEP_SND);
  66.  
  67.         dummy := SndPlay(nil, soundHandle, SYNCHRONOUS);
  68.  
  69.         soundHandle := GetResource('snd ', MONKEY_SND);
  70.  
  71.         if soundHandle = nil then
  72.             ErrorHandler(CANT_LOAD_MONKEY_SND);
  73.  
  74.         dummy := SndPlay(nil, soundHandle, SYNCHRONOUS);
  75.  
  76.         soundHandle := GetResource('snd ', KLANK_SND);
  77.  
  78.         if soundHandle = nil then
  79.             ErrorHandler(CANT_LOAD_KLANK_SND);
  80.  
  81.         dummy := SndPlay(nil, soundHandle, SYNCHRONOUS);
  82.  
  83.         soundHandle := GetResource('snd ', BOING_SND);
  84.  
  85.         if soundHandle = nil then
  86.             ErrorHandler(CANT_LOAD_BOING_SND);
  87.  
  88.         dummy := SndPlay(nil, soundHandle, SYNCHRONOUS);
  89.     end;
  90.  
  91.  
  92. {-------------------------------->    Sounder    <---}
  93.  
  94. begin
  95.     MakeSound;
  96. end.